package com.mdnote.practice.bit;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/10/17
 * @description 颠倒二进制位
 */
public class LeetCode190 {

    public int reverseBits(int n) {
        if (n == 0 || n == -1) {
            return n;
        }
        int p = 31;
        int res = 0;
        while (n != 0) {
            res +=  (n & 1) << p;
            // 算术位移
            n = n >>> 1;
            p--;
        }

        return res;
    }
}
